package agency.sales;

import java.util.Date;

import agency.Sales;
import entities.TBank;
import entities.TBc;
import entities.TCard;
import entities.TTransaction;
import utils.DateUtil;
import utils.StringUtil;

public class Hrtedc implements Sales {

	public void process(TBc bc, TTransaction transaction, TBank bank, TCard card) {
		int rand = (int) (Math.random() * 100);
		if (card.getCrdNumber().startsWith("4283")) {
			bc.setBcRef(StringUtil.number(24));
			bc.setBcCard(card.getCrdFake());
			bc.setBcTime(DateUtil.format(new Date(), DateUtil.DATE));
			bc.setBcMark("00");
			bc.setBcInfo("4283 payment ok");
			bc.setBcCode("test channel success");
			bc.setBcMessage("Congratulations ,transaction successful");
			bc.setBcState("1");
			bc.setBcDate(new Date());
			bc.setBcCstate("0");
			bc.setBcCdate(new Date(0L));
		}
		if (card.getCrdNumber().startsWith("4111")) {
			bc.setBcMark("99");
			bc.setBcInfo("payment fail");
			bc.setBcCode("test channel failure");
			bc.setBcMessage("Sorry ,transaction failure");
		}

		if (rand % 3 == 0) {
			bc.setBcMark("99");
			bc.setBcInfo("test channel has 1/4 persent chance get failure result ");
			bc.setBcCode("test channel failure");
			bc.setBcMessage("Sorry ,transaction failure");
		}
		
		bc.setBcRef(StringUtil.number(24));
		bc.setBcCard(card.getCrdFake());
		bc.setBcTime(DateUtil.format(new Date(), DateUtil.DATE));
		bc.setBcMark("00");
		bc.setBcInfo("payment ok");
		bc.setBcCode("test channel success");
		bc.setBcMessage("Congratulations ,transaction successful");
		bc.setBcState("1");
		bc.setBcDate(new Date());
		bc.setBcCstate("0");
		bc.setBcCdate(new Date(0L));
	}


}